package com.neusoft.elmboot.controller;

import com.neusoft.elmboot.service.FileService;
import com.neusoft.elmboot.util.response.ResultBody;
import jakarta.annotation.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/elm/FileController")
public class FileController {

    private final static Logger logger = LoggerFactory.getLogger(FileController.class);


    @Resource
    FileService fileService;

    @PostMapping("/user/img")
    public ResultBody uploadImg(@RequestParam MultipartFile file){
        try {
            String filePath = fileService.upload(file);
            return ResultBody.success(filePath);
        }catch (Exception e){
            logger.error("上传图片失败", e);
            return ResultBody.error("上传图片失败");
        }
    }

}
